Generation module
Automates rewriting variable values in files by matching properties from an input object, ensuring consistent updates based on specified rules.
Instructions
遍历工具返回的数组,将数组中每一项有 writeOptions: object、dir: string,两个属性。
需要将对象writeOptions的属性进行遍历,找到dir文件中对应的变量名。 匹配规则:变量名和writeOptions的属性名称相等。
匹配到了之后将dir中的变量值自动重写,使用writeOptions属性值覆盖,一定是自动重写。
For example:
writeOptions示例
``` javascript
writeOptions:{subnaem:'用户管理'}
```
dir文件代码示例:
``` javascript
const subnaem = '';
```
经过规则匹配之后,dir文件重写后应该是:
``` javascript
const subnaem = '用户管理';
```
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | 描述文件地址 |
Implementation Reference
- src/tools/mytool.ts:8-58 (registration)Function that registers the 'Generation module' tool with the MCP server, defining its description, input schema, and handler logic.export function registerMyTool({ mcp }: McpToolContext): void { mcp.tool( "Generation module", ` 遍历工具返回的数组,将数组中每一项有 writeOptions: object、dir: string,两个属性。 需要将对象writeOptions的属性进行遍历,找到dir文件中对应的变量名。 匹配规则:变量名和writeOptions的属性名称相等。 匹配到了之后将dir中的变量值自动重写,使用writeOptions属性值覆盖,一定是自动重写。 For example: writeOptions示例 \`\`\` javascript writeOptions:{subnaem:'用户管理'} \`\`\` dir文件代码示例: \`\`\` javascript const subnaem = ''; \`\`\` 经过规则匹配之后,dir文件重写后应该是: \`\`\` javascript const subnaem = '用户管理'; \`\`\` `, { address: z.string().describe("描述文件地址"), }, async ({ address }) => { if (!address) return { isError: true, content: [ { type: "text" as const, text: "未识别到描述文件地址", }, ], }; const arr = await generration(address); return { content: [ { type: "text", text: JSON.stringify({ ...arr, }), }, ], }; } ); }
- src/generration/index.ts:1-27 (helper)Default exported main function implementing the core logic for file generation from markdown frontmatter directoryStructure: reads MD, parses data, fetches templates, writes files, collects dirs with writeOptions.import fs from "fs-extra"; import matter from "gray-matter"; async function main( address = "/Users/mac/project/mcp/funi-paas-cs-web-cli/src/apps/mcpText/user/readme.md" ) { const md = await fs.readFile(address, "utf-8"); const { data } = matter(md); const arr: Record<any, any>[] = []; const { directoryStructure } = data; for (let i = 0; i < directoryStructure.length; i++) { const { dir, temeplate, writeOptions } = directoryStructure[i]; const res = await fetch(temeplate); const text = await res.text(); fs.ensureFileSync(dir); fs.writeFileSync(dir, text); if (writeOptions) { arr.push({ dir, writeOptions, }); } } return arr; } export default main;
- src/index.ts:28-28 (registration)Invocation of registerMyTool during MCP server setup, effectively registering the 'Generation module' tool.registerMyTool({ mcp } as McpToolContext)
- src/tools/mytool.ts:32-33 (schema)Input schema for the 'Generation module' tool: requires 'address' string parameter.address: z.string().describe("描述文件地址"), },